 package com.stork.sms.activity;
import android.annotation.TargetApi;
import android.app.ActionBar;
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

import com.stork.sms.R;
import com.stork.sms.fragment.AddressView;
import com.stork.sms.fragment.MapView;

public class Contactus extends Activity {
	
	TextView addressViewText,mapViewText;
	Fragment addressViewFragment,mapViewFragment;
	ActionBar ab;
	
	@TargetApi(Build.VERSION_CODES.HONEYCOMB)
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_contactus);				
				
		ab=getActionBar();
		ab.setDisplayHomeAsUpEnabled(true);
		ab.setTitle("Contacus");
		
		addressViewText=(TextView)findViewById(R.id.addressviewtextView1);
		mapViewText=(TextView)findViewById(R.id.mapviewtextView2);
		
		addressViewFragment=new AddressView();
		FragmentManager fm=getFragmentManager();
		FragmentTransaction ft=fm.beginTransaction().replace(R.id.contactfragement, addressViewFragment);
		ft.commit();				
		addressViewText.setBackgroundResource(R.color.none);
		mapViewText.setBackgroundResource(R.color.white);
		addressViewText.setTextColor(Color.WHITE);
		mapViewText.setTextColor(Color.BLACK);
		
		
addressViewText.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				
				addressViewFragment=new AddressView();
				FragmentManager fm=getFragmentManager();
				FragmentTransaction ft=fm.beginTransaction().replace(R.id.contactfragement, addressViewFragment);
				ft.commit();				
				addressViewText.setBackgroundResource(R.color.none);
				mapViewText.setBackgroundResource(R.color.white);
				addressViewText.setTextColor(Color.WHITE);
				mapViewText.setTextColor(Color.BLACK);
				
			}		
		});
		
mapViewText.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				
				mapViewFragment=new MapView();
				FragmentManager fm=getFragmentManager();
				FragmentTransaction ft=fm.beginTransaction().replace(R.id.contactfragement, mapViewFragment);
				ft.commit();
				ab.setTitle("Contacus MapView");
				addressViewText.setBackgroundResource(R.color.white);
				mapViewText.setBackgroundResource(R.color.none);
				mapViewText.setTextColor(Color.WHITE);
				addressViewText.setTextColor(Color.BLACK);
								
			}		
		});
		
			
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.contactus, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// TODO Auto-generated method stub		
		
		switch(item.getItemId())
		{
		
		case android.R.id.home:
			super.onBackPressed();
			return true;
			
		case R.id.action_logout:
			
			Intent log=new Intent(Contactus.this, Login.class);
			startActivity(log);
			return true;
			
		}
			
			return super.onOptionsItemSelected(item);			
	}
}
